package com.example.yeujian5.yuejian5.fragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.yeujian5.yuejian5.Listenner.UserAllOrderListener;
import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.adapter.UserAllOrderListAdapter;
import com.example.yeujian5.yuejian5.bean.UserOrder;
import com.example.yeujian5.yuejian5.model.UserModel;

import java.util.List;


public class AllOrderFragment extends Fragment {
    private RecyclerView recyclerView;
    private String userid;
    List<UserOrder> list;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_allorder,container,false);
        initView(view);
        getUserId();
        showData();
        return view;
    }

    public  void initView(View view){
        recyclerView = (RecyclerView) view.findViewById(R.id.allorder_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    private void showData(){
        UserModel model=new UserModel();
        model.getAllOrderByUser(userid,usercollectListener);
    }

    UserAllOrderListener usercollectListener=new UserAllOrderListener(){
        @Override
        public void onResponse(List<UserOrder> listBean) {
            list=listBean;
            recyclerView.setAdapter(new UserAllOrderListAdapter(getActivity(),list));
        }

        @Override
        public void onFail(String msg) {

        }
    };

    private void getUserId(){
        userid = getActivity().getSharedPreferences("Userid", Context.MODE_PRIVATE).getString("user_id", String.valueOf(0));
        Log.v("AllOrder获取用户id", String.valueOf(userid));
    }
}
